package com.wskeee.ec.components
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import com.wskeee.ec.core.SkinableComponent;
	import com.wskeee.ec.styles.DefaultStyle;
	import com.wskeee.ec.styles.StyleNames;
	
	public class BasePanel extends SkinableComponent
	{
		public function BasePanel()
		{
			super();
			border = true;
		}
		
		//--------------------------------------------------------------------------
		//
		//  variables
		//
		//--------------------------------------------------------------------------
		
		
		//--------------------------------------------------------------------------
		//
		//  init
		//
		//--------------------------------------------------------------------------
		
		//---------------------
		//initEvent
		//---------------------
		override protected function initEvent():void
		{
			super.initEvent();
			addEventListener(Event.RESIZE,onResizeHandler);
		}
		
		private function onResizeHandler(evt:Event):void
		{
			drawBackgrounpChanged = true;
			invalidateDisplayList();
		}
		
		private function destoryEvent():void
		{
			removeEventListener(Event.RESIZE,onResizeHandler);
		}
		
		//--------------------------------------------------------------------------
		//
		//  styles
		//
		//--------------------------------------------------------------------------
		
		//---------------------
		//drawBackgrounpChanged
		//---------------------
		private var drawBackgrounpChanged:Boolean = false;
		
		//---------------------
		//backgrounpColor
		//---------------------
		private var _backgrounpColor:Object = 0xffffff;
		public function set backgrounpColor(value:Object):void
		{
			_backgrounpColor = value;
			drawBackgrounpChanged = true;
			invalidateDisplayList();
		}

		public function get backgrounpColor():Object
		{
			return _backgrounpColor;
		}

		//---------------------
		//backgrounpAlpha
		//---------------------
		private var _backgrounpAlpha:Number=1;
		public function get backgrounpAlpha():Number
		{
			return _backgrounpAlpha;
		}
		
		public function set backgrounpAlpha(value:Number):void
		{
			_backgrounpAlpha = value;
			drawBackgrounpChanged = true;
			invalidateDisplayList();
		}
		
		//--------------------------------------------------------------------------
		//
		//  public Method
		//
		//--------------------------------------------------------------------------
		
		override public function destory():void
		{
			destoryEvent();
			super.destory();
		}
		
		//--------------------------------------------------------------------------
		//
		//  Invalidate Method
		//
		//--------------------------------------------------------------------------
		
		//---------------------
		//updateDisplayList
		//---------------------
		override protected function updateDisplayList():void
		{
			super.updateDisplayList();
			if(drawBackgrounpChanged)
			{
				drawBackgrounpChanged = false;
				drawBackgrounp();
			}
		}
		
		//--------------------------------------------------------------------------
		//
		//  protected Method
		//
		//--------------------------------------------------------------------------
		
		//---------------------
		//redrawSkin
		//---------------------
		/**
		 * 样式或者手动更新皮肤时调用 
		 * 
		 */
		override protected function redrawSkin():void
		{
			super.redrawSkin();
			filters = shadow ? [DefaultStyle.getShadow(2,true)] : [];
		}
		
		//---------------------
		//backgrounp
		//---------------------
		protected function drawBackgrounp():void
		{
			graphics.clear();
			if(border)
				graphics.lineStyle(1,getStyle(StyleNames.BORDER_COLOR) as uint,0.2);
			graphics.beginFill(backgrounpColor as uint,backgrounpAlpha);
			graphics.drawRect(0,0,width,height);
		}
		
		//--------------------------------------------------------------------------
		//
		//  children
		//
		//--------------------------------------------------------------------------
		//-----------------------------------------------------------------
		//  contentContainer
		//-----------------------------------------------------------------
		/**
		 * 用于储存子对象 
		 */
		protected var content:Sprite;
	}
}